/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import okio from 'okio';

export default {
    data: {
        title: "",
        writeUtfValue: "",
        writeIntValue: "",
        writeStringValue: "",
        writeShortValue: "",
        writeIntLeValue: "",
        writeShortLeValue: "",
        writeByteValue: "",
        writeUtf8CodePointValue: "",
        writeUtf8ByteCountValue: "",
        writableSegmentValue: "",
        readUtfValue: "",
        readInt: "",
        readString: "",
        readIntLe: "",
        readShortLe: "",
        readShort: "",
        readByte: "",
        readUtf8CodePointValue: "",
        readUtf8ByteCountValue: ""
    },
    onInit() {
        this.validateokio();
    },
    getStringUtfValue(e) {
        this.writeUtfValue = e.text;
    },
    getWriteIntValue(e) {
        this.writeIntValue = e.text;
    },
    getWriteStringValue(e) {
        this.writeStringValue = e.text;
    },
    getWriteShortValue(e) {
        this.writeShortValue = e.text;
    },
    getWriteIntLeValue(e) {
        this.writeIntLeValue = e.text;
    },
    getWriteShortLeValue(e) {
        this.writeShortLeValue = e.text;
    },
    getWriteByteValue(e) {
        this.writeByteValue = e.text;
    },
    getUtf8CodePointValue(e) {
        this.writeUtf8CodePointValue = e.text;
    },
    getWritableSegmentValue(e) {
        this.writableSegmentValue = e.text;
    },
    getUtf8ByteCountValue(e) {
        this.writeUtf8ByteCountValue = e.text;
    },
    performWriteUtf8() {
        var buffer = new okio.Buffer();

        buffer.writeUtf8(this.writeUtfValue);
        this.readUtfValue = buffer.readUtf8();
    },
    performWriteInt() {
        var buffer = new okio.Buffer();
        buffer.writeInt(this.writeIntValue);
        this.readInt = buffer.readInt();
    },
    performWriteString() {
        var buffer = new okio.Buffer();
        buffer.writeString(this.writeStringValue);
        this.readString = buffer.readString();
    },
    performWriteIntLe() {
        var buffer = new okio.Buffer();
        buffer.writeIntLe(this.writeIntLeValue);
        this.readIntLe = buffer.readIntLe();
    },
    performWriteShortLe() {
        var buffer = new okio.Buffer();
        buffer.writeShortLe(this.writeShortLeValue);
        this.readShortLe = buffer.readShortLe();
    },
    performWriteShort() {
        var buffer = new okio.Buffer();
        buffer.writeShort(this.writeShortValue);
        this.readShort = buffer.readShort();
    },
    performWriteByte() {
        var buffer = new okio.Buffer();
        buffer.writeByte(this.writeByteValue)
        this.readByte = buffer.readByte();
    },
    performWriteUtf8CodePoint() {
        var buffer = new okio.Buffer();
        buffer.writeUtf8CodePoint(this.writeUtf8CodePointValue);
        this.readUtf8CodePointValue = buffer.readUtf8CodePoint();
    },
    performWriteUtf8ByteCount() {
        var buffer = new okio.Buffer();

        buffer.writeUtf8(this.writeUtf8ByteCountValue);
        this.readUtf8ByteCountValue = buffer.readUtf8ByteCount(buffer.size);
    },
    validateokio() {
        var buffer = new okio.Buffer();

        buffer.writeUtf8("test");

        buffer.writeInt(10);

        buffer.writeString("Test");

        buffer.writeIntLe(100);

        buffer.writeShortLe(100);

        buffer.writeShort(25);

        buffer.writeByte(9);

        buffer.writeUtf8CodePoint(99);
    }
}
